# -*- coding: utf-8 -*-
"""
file:ch6_2定积分-面积图
author: Fuwen
time: 2022/7/17 20:25
software:PyCharm
"""
import numpy as np
import matplotlib.pyplot as plt

# ∫(x + 1)dx, x∈[1,5]
# ∫(x + 1)dx = F(5) - F(1)
# F(x) = 0.5 * x² + x
# 定积分≈几何图形的面积 = 反导函数|原函数 区间上下限值之间的函数值之差

# 积分函数的系数f(x)
a, b = 1, 1

# 绘制积分区间的图形面积
x = np.linspace(0, 6, 1000)
y = a * x + b
plt.plot(x, y, 'r')
plt.fill_between(x, y1=y, y2=0, where=(x>=1)&(x<=5), facecolor='lightgreen')

plt.grid()
plt.show()